package com.pp.manage.mapper;

import com.pp.manage.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * @author yangfan
 * @date 2020/7/14 12:09
 * @description
 */

@Mapper
@Repository("userMapper")
public interface UserMapper {

    @Insert("INSERT INTO user(mobile,password,sex,birthdate,address,email,state,create_time,update_time) VALUES (#{mobile},#{password},#{sex},#{birthdate},#{address},#{email},#{state},#{create_time},#{update_time})")
    int insertUser(User user);

    @Update("UPDATE user SET state = -1 WHERE id = #{userId}")
    int deleteUserTemporary(@PathVariable Integer userId);

    @Delete("DELETE FROM user WHERE id = #{userId}")
    int deleteUser(@PathVariable Integer userId);

    @Update("UPDATE user SET mobile=#{mobile},password=#{password},sex=#{sex},birthdate=#{birthdate},address=#{address},email=#{email},update_time=#{update_time} WHERE id = #{id} AND state = 1")
    boolean updateUser(User user);

    @Select("SELECT id,mobile,password,sex,birthdate,address,email,state,create_time,update_time FROM user WHERE id = #{userId} AND state = 1")
    User findUserById(@PathVariable Integer userId);

    @Select("SELECT id,mobile,password,sex,birthdate,address,email,state,create_time,update_time FROM user WHERE state = 1")
    List<User> findAllUser();
}
